package serverMgr

import (
	"errors"
	"src/zeus/iserver"

	clientv3 "go.etcd.io/etcd/client/v3"
)

var (
	dismgr *DiscoveryMgr
)

// GetServerMgr 获取服务器管理实例
func GetServerMgr() *DiscoveryMgr {
	if dismgr == nil {
		panic("DiscoveryMgr is not Init")
	}
	return dismgr
}

// ErrServerBusy 服务器忙
var ErrServerBusy = errors.New("Get server failed, busy")

type IServerMap interface {
	//加入服务器信息
	Put(sinfo *iserver.ServerInfo)
	//更新Load值
	UpLoad(path string, val int64) *iserver.ServerInfo
	//根据负载逻辑，获取服务器
	GetBalancing(groupid uint32, stype uint8) (result *iserver.ServerInfo, err error)
	//获取所有服务器
	GetServerList(sGroup uint32, sType uint8) ([]iserver.ServerInfo, error)
	//获取指定服务器
	GetServerByID(groupid uint32, stype uint8, serverId uint64) (result *iserver.ServerInfo, err error)

	//删除一个服务器信息
	Delete(path string)
	//删除所有服务器信息
	DeleteAll()
	// 监听函数
	WatchCallDelay(evt *clientv3.Event)
	LoadWatchAll(key string)
}

const (
	// 服务器状态 默认
	SERVER_STATE_DEFAULT int = 0
	// 服务器状态 锁定
	SERVER_STATE_LOCK int = 1
)
